package com.qf.test;

import com.qf.bean.Student;
import com.qf.dao.StudentDao;
import com.qf.util.SessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 2019/11/9
 * Administrator
 * mybatis002
 * 面向对象面向君  不负代码不负卿
 */
public class Demo1 extends SessionUtils {

    //测试
    @Test
    public void a1(){
      /*  SqlSession sqlSession = getsession();
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        Student student = new Student(null, "梁田", "男", "唱歌");
        int i = mapper.insertStudent(student);
        sqlSession.commit();
        System.out.println(i);
        System.out.println("id="+student.getSid());
        closesession();*/
    }


    @Test
    public void b1(){
        SqlSession sqlSession = getsession();
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        List<Student> students = mapper.findall();
        for (Student student : students) {
            System.out.println(student);
        }
        closesession();
    }

    @Test
    public void c1(){
        SqlSession sqlSession = getsession();
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        Map map=new HashMap();
        map.put("sname",null);
        map.put("spass",null);
        List<Student> students = mapper.findbynameAndPassword(map);
        for (Student student : students) {
            System.out.println(student);
        }
        closesession();
    }
}
